from django.db import models

class Pathway(models.Model):
    pathid = models.IntegerField(primary_key=True)
    name = models.CharField(max_length=100)
    category = models.CharField(max_length=100, blank=True)
    def __str__(self):
      return self.name
    def get_absolute_url(self):
      return "http://csb.inf.ed.ac.uk/pathway/%s/" % self.name
    class Meta:
        db_table = u'pathway'
    class Admin:
        # Admin options go here
        list_display = ('pathid', 'name', 'category', )
        ordering = ('pathid',)
        search_fields = ('name',)         

class Reaction(models.Model):
    reactionid = models.CharField(max_length=6, primary_key=True)
    pathway = models.ForeignKey(Pathway)
    reversibility = models.CharField(max_length=1, blank=True)
    main_compound = models.CharField(max_length=100, blank=True)
    equation = models.CharField(max_length=300, blank=True)
    eq_in_id = models.CharField(max_length=150, blank=True)
    def __str__(self):
      return self.reactionid
    class Meta:
        db_table = u'reaction'
        ordering = ('pathway', 'reactionid',)
    class Admin:
        # Admin options go here
        list_display = ('reactionid', 'pathway', 'reversibility', 'equation')
        list_per_page = 100
        list_filter = ('pathway', 'reversibility')
        ordering = ('pathway', 'reactionid',)
        search_fields = ('reactionid','eq_in_id','equation',)         

class Compound(models.Model):
    compoundid = models.CharField(max_length=6, primary_key=True)
    name = models.CharField(max_length=300, blank=True)
    formula = models.CharField(max_length=300, blank=True)
    keggid = models.CharField(max_length=6, blank=True)
    empid = models.CharField(max_length=6, blank=True)
    cas = models.CharField(max_length=100, blank=True)
    pubchem = models.CharField(max_length=8, blank=True)
    chebi = models.CharField(max_length=6, blank=True)
    hmdb = models.CharField(max_length=9, blank=True)
    smile = models.CharField(max_length=1000, blank=True)
    inchi = models.CharField(max_length=1000, blank=True)
    def __str__(self):
      return self.compoundid
#    def __unicode__(self):
 #     return u'%s %s' (self.compoundid, self.name)
    class Meta:
        # the db-table meta class define the table name
        db_table = u'compound'
    class Admin:
        # Admin options go here
        list_display = ('compoundid', 'formula', 'name')
        ordering = ('compoundid',)
        search_fields = ('compoundid','name',)         

class Gene(models.Model):
    geneid = models.CharField(max_length=10,primary_key=True)
    name = models.CharField(max_length=25, blank=True)
    synonym = models.CharField(max_length=200,blank=True)
    chromosome=models.CharField(max_length=8,blank=True)
    maploc=models.CharField(max_length=40,blank=True)
    description=models.CharField(max_length=300,blank=True)
    fullname=models.CharField(max_length=200,blank=True)
    hgnc=models.CharField(max_length=5,blank=True)
    ensembl=models.CharField(max_length=20,blank=True)
    omim=models.CharField(max_length=300,blank=True)
    unigene=models.CharField(max_length=100,blank=True)
    gi=models.CharField(max_length=400,blank=True)
    hprd=models.CharField(max_length=40,blank=True)
    uniprot=models.CharField(max_length=550,blank=True)
    altprotein=models.CharField(max_length=400,blank=True)
    def __str__(self):
      return self.geneid
    class Meta:
        db_table = u'gene'
    class Admin:
        # Admin options go here
        list_display = ('geneid', 'name', 'omim')
        ordering = ('geneid', )
        search_fields = ('geneid','name',)
        
class Humap(models.Model): #human gene protein mapping
    entrezid = models.CharField(max_length=10,blank=True)
    name = models.CharField(max_length=25, blank=True)
    synonym = models.CharField(max_length=200,blank=True)
    chromosome=models.CharField(max_length=8,blank=True)
    maploc=models.CharField(max_length=40,blank=True)
    start=models.CharField(max_length=20,blank=True)
    end=models.CharField(max_length=20,blank=True)
    direction=models.CharField(max_length=2,blank=True)
    description=models.CharField(max_length=300,blank=True)
    type=models.CharField(max_length=50,blank=True)
    hgnc=models.CharField(max_length=5,blank=True)
    ensembl=models.CharField(max_length=60,blank=True)
    omim=models.CharField(max_length=300,blank=True)
    hprd=models.CharField(max_length=40,blank=True)
    unigene=models.CharField(max_length=100,blank=True)
    gi=models.CharField(max_length=400,blank=True)
    ipi=models.CharField(max_length=1850,blank=True)
    swprot=models.CharField(max_length=550,blank=True)
    trembl=models.CharField(max_length=6000,blank=True)
    enspep=models.CharField(max_length=1850,blank=True)
    hinvdb=models.CharField(max_length=400,blank=True)
    ccds=models.CharField(max_length=550,blank=True)
    vegag=models.CharField(max_length=550,blank=True)
    vegap=models.CharField(max_length=3850,blank=True)
    def __str__(self):
      return self.name
    class Meta:
        db_table = u'humap'
    class Admin:
        # Admin options go here
        list_display = ('entrezid', 'name', 'omim')
        ordering = ('entrezid', )
        search_fields = ('entrezid','name',)

class Morbid(models.Model):
    gene = models.ForeignKey(Gene)
    disorder = models.CharField(max_length=200,blank=True)
#    def __unicode__(self):
#      return u'%s %s' (self.reaction, self.gene)
    class Meta:
        db_table = u'morbid'
    class Admin:
        list_display = ('gene', 'disorder',)
        list_per_page = 100
        ordering = ('gene',)
        search_fields = ('disorder','gene',)         

class Dis_target(models.Model):
    disease = models.CharField(max_length=200,blank=True)
    gene = models.ForeignKey(Gene)
#    def __unicode__(self):
#      return u'%s %s' (self.reaction, self.gene)
    class Meta:
        db_table = u'dis_target'
    class Admin:
        list_display = ('gene', 'disease',)
        list_per_page = 100
        ordering = ('gene',)
        search_fields = ('disease','gene',)         

class Drug_target(models.Model):
    gene = models.ForeignKey(Gene)
    drug = models.CharField(max_length=200,blank=True)
    drugtype = models.CharField(max_length=15,blank=True)
#    def __unicode__(self):
#      return u'%s %s' (self.reaction, self.gene)
    class Meta:
        db_table = u'drug_target'
    class Admin:
        list_display = ('gene', 'drug',)
        list_per_page = 100
        ordering = ('gene',)
        search_fields = ('drug','gene',)         

class Rea_comp(models.Model):
#serial primary key generated automatically
    SUB_CHOICES = (
        ('S', 'Substrate'),
        ('P', 'Product'),
        )
    reaction = models.ForeignKey(Reaction)
    compound = models.ForeignKey(Compound)
    sub_pro = models.CharField(max_length=1, choices=SUB_CHOICES)
    maincompound = models.CharField(max_length=1, blank=True)
    coefficient = models.CharField(max_length=3, blank=True)
#    def __unicode__(self):
#      return u'%s %s' (self.reaction, self.compound)
    class Meta:
        db_table = u'rea_comp'
    class Admin:
        list_display = ('reaction', 'compound', 'sub_pro', 'maincompound',)
        list_per_page = 100
        list_filter = ('maincompound',)
        ordering = ('reaction',)
        search_fields = ('reaction','compopund','equation',)         

class Rea_gene(models.Model):
    reaction = models.ForeignKey(Reaction)
    gene = models.ForeignKey(Gene)
#    def __unicode__(self):
#      return u'%s %s' (self.reaction, self.gene)
    class Meta:
        db_table = u'rea_gene'
    class Admin:
        list_display = ('reaction', 'gene',)
        list_per_page = 100
        ordering = ('reaction',)
        search_fields = ('reaction','gene',)         

class Rea_ec(models.Model):
    reaction = models.ForeignKey(Reaction)
    enzyme = models.CharField(max_length=20)
#    def __unicode__(self):
#      return u'%s %s' (self.reaction, self.enzyme)
    def __str__(self):
      return self.enzyme
    class Meta:
        db_table = u'rea_ec'
    class Admin:
        list_display = ('reaction', 'enzyme',)
        list_per_page = 100
        ordering = ('reaction',)
        search_fields = ('reaction','enzyme',)         

class Gene_ec(models.Model):
    gene = models.ForeignKey(Gene)
    enzyme = models.CharField(max_length=20)
#    def __unicode__(self):
#      return u'%s %s' (self.gene, self.enzyme)
    class Meta:
        db_table = u'gene_ec'
    class Admin:
        list_display = ('gene', 'enzyme',)
        list_per_page = 100
        ordering = ('gene',)
        search_fields = ('gene','enzyme',)         

class Location(models.Model):
    id = models.IntegerField(primary_key=True)
    goid = models.CharField(max_length=10)
    des = models.CharField(max_length=30)
    abs = models.CharField(max_length=4)
    def __str__(self):
      return self.des
    class Meta:
        db_table = u'location'
    class Admin:
        # Admin options go here
        list_display = ('goid', 'des', 'abs', )

class Geneloc(models.Model):
    gene = models.ForeignKey(Gene)
    loc = models.ForeignKey(Location)
    class Meta:
        db_table = u'geneloc'
    class Admin:
        list_display = ('gene', 'loc',)

class Realoc(models.Model):
    rea = models.ForeignKey(Reaction)
    loc = models.ForeignKey(Location)
    class Meta:
        db_table = u'realoc'
    class Admin:
        list_display = ('rea', 'loc',)

class GO(models.Model):
    id = models.CharField(max_length=20,primary_key=True)
    des=models.CharField(max_length=100,blank=True)
    namespace=models.CharField(max_length=20,blank=True)
    def __str__(self):
      return self.id
    class Meta:
        db_table = u'go'
    class Admin:
        list_display = ('id', 'des',)
# make use of the GO-subset relationship to make use of different GO slim terms for visualization        
class Gene_go(models.Model):
    gene = models.ForeignKey(Gene)
#    go = models.ForeignKey(Go)
    go = models.CharField(max_length=20)
    des =models.CharField(max_length=80,blank=True) #remove if GO as foreign ID
    evidence=models.CharField(max_length=4,blank=True)
    pubmed=models.CharField(max_length=40,blank=True)
    class Meta:
        db_table = u'gene_go'
    class Admin:
        list_display = ('gene', 'go',)
        
class Go_link(models.Model):
    go1 = models.ForeignKey(GO, related_name = "go1")
    go2 = models.ForeignKey(GO, related_name = "go2")
    relation=models.CharField(max_length=20,blank=True)
    class Meta:
        db_table = u'go_link'
    class Admin:
        list_display = ('go1', 'go2','relation',)

class Met_link(models.Model):
    com1 = models.ForeignKey(Compound, related_name = "substrate")
    com2 = models.ForeignKey(Compound, related_name = "product")
    rea=models.ForeignKey(Reaction)
    pathway=models.ForeignKey(Pathway, blank=True)
#    def __unicode__(self):
#      return u'%s %s' (self.gene, self.enzyme)
    class Meta:
        db_table = u'met_link'
    class Admin:
        list_display = ('com1', 'com2','rea',)
        list_per_page = 100
        ordering = ('com1',)
        search_fields = ('com1','com2','rea',)         

class Realocation(models.Model):
    reactionid = models.CharField(max_length=7, primary_key=True)
    rea=models.ForeignKey(Reaction,blank=True) #for transport reactions, empty
    pathway = models.ForeignKey(Pathway)
    loc=models.ForeignKey(Location,blank=True) #for transport reactions, empty)
#    reversibility = models.CharField(max_length=1, blank=True)
    reversibility = models.CharField(max_length=1, blank=True)
    main_compound = models.CharField(max_length=100, blank=True)
    equation = models.CharField(max_length=300, blank=True)
    eq_in_id = models.CharField(max_length=150, blank=True)
    def __str__(self):
      return self.realocid
    class Meta:
        db_table = u'realocation'

class Complocation(models.Model):
    compoundid = models.CharField(max_length=7, primary_key=True)
    comp = models.ForeignKey(Compound)
    name = models.CharField(max_length=300, blank=True)
    loc=models.ForeignKey(Location)
    def __str__(self):
      return self.complocid
    class Meta:
        db_table = u'complocation'

class Rea_complocation(models.Model):
#serial primary key generated automatically
    SUB_CHOICES = (
        ('S', 'Substrate'),
        ('P', 'Product'),
        )
    reaction = models.ForeignKey(Realocation)
    compound = models.ForeignKey(Complocation)
    sub_pro = models.CharField(max_length=1, choices=SUB_CHOICES)
    maincompound = models.CharField(max_length=1, blank=True)
    coefficient = models.CharField(max_length=3, blank=True)
#    def __unicode__(self):
#      return u'%s %s' (self.reaction, self.compound)
    class Meta:
        db_table = u'reacomplocation'

class Rea_genelocation(models.Model):
    reaction = models.ForeignKey(Realocation)
    gene = models.ForeignKey(Gene)
    class Meta:
        db_table = u'reagenelocation'

class Met_linklocation(models.Model):
    com1 = models.ForeignKey(Complocation, related_name = "substrate")
    com2 = models.ForeignKey(Complocation, related_name = "product")
    rea=models.ForeignKey(Realocation)
    pathway=models.ForeignKey(Pathway, blank=True)
    location=models.ForeignKey(Location, blank=True)
    reversibility = models.CharField(max_length=1, blank=True)
#    def __unicode__(self):
#      return u'%s %s' (self.gene, self.enzyme)
    class Meta:
        db_table = u'met_linklocation'